package com.gqzdev.shiro.service;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.session.Session;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @ClassName: ShiroService
 * @author: ganquanzhong
 * @date: 2020/5/29 10:44
 *
 * 测试Shiro的注解配置
 * @RequestRoles()
 *
 */

@Component
public class ShiroService {

    @RequiresRoles(value = {"admin"},logical = Logical.OR)
    public void testMethod(){
        System.out.println("testMethod, time: " + new Date());

        Session session = SecurityUtils.getSubject().getSession();
        Object val = session.getAttribute("key");

        System.out.println("Service SessionVal: " + val);

    }
}
